<?php
/*
* Kusht Mud.
* ----
* The MIT License
* Copyright (c) 2010 Andrew Tutt
* ----
*/

/* Commands
*
* This Class Gives Functionality to All of the Game's Commands
*/

/* These commands are overloaded in the architecture in that
* all characters, including NPCs, can issue commands (a good thing)
* so $user could be a userCharacter extends Character or it could be
* a vanilla "Character" object. Pretty neat. */

/* Every time you add a command, you must add a function here. That command
* is automatically associated to the function of the same name */

/* require_once "helperFunctions.inc"; (indirect via run.php) */

class commands {

	public static $CMDLIST = array("gossip",
								   "say",
								   "tell",
								   "quit");

	public static $ABBREVS = array("'" => "say");

	/* Associated Functions ------------- */

	/* Communication Functions */
	// Generic Talk Channel
	public static function talk_channel($user, $phrase, $channel, $verb) {
		return;
	}

	// This is the Precise and Proper Implementation of the 'Gossip' Function
	public static function gossip($user,$phrase) {
		if ($phrase == "") {
			$user->send("Gossip what?");
			return;
		}
		
		$user->send("You gossip, \"".$phrase."\"");
		$users = world::$char_list;
		
		foreach ($users as $oUser) {
			if($oUser!==$user) {
				$oUser->send($user->name." gossips, \"".$phrase."\"");
			}
		}
	}

	public static function say($user,$phrase) {
		if ($phrase == "") {
			$user->send("Say what?");
			return;
		}
		
		cmdHandler::act ($user,"?n says '?T'.", NULL, $phrase, TO_ROOM);
		cmdHandler::act ($user,"You say '?T'.", NULL, $phrase, TO_CHAR);
		
		/* We'll Eventually Toss off a Trigger here too to complete this function */

	}
	
	public static function tell($user,$phrase) {
		$arg = cmdHandler::splitReturnNextArg($phrase);
		
		if ($arg=="" || $phrase=="") {
			$user->send("Tell whom what?");
			return;
		}
		
		$target = world::get_char_world($user,$arg);
				
		if (!$target) {
			$user->send("They aren't here.");
			return;
		}
		
		cmdHandler::act ($user,"You tell ?N '?t'.", $phrase, $target, TO_CHAR);
		cmdHandler::act ($user,"?n tells you '?t'.", $phrase, $target, TO_TARG);
		$target->reply = $user;
	}


	/* Observation Functions */

	public static function look($user,$phrase) {
		if ($phrase=="") {
			$user->addtobuffer("~",ROOM_CONTAINER_OPEN); // Toss away the ~ on the client side
			if ($user->in_room->image) { $user->addtobuffer($user->in_room->image,ROOM_IMG); }
			$user->addtobuffer($user->in_room->name,ROOM_NAME);
			$user->addtobuffer($user->in_room->description,ROOM_DESC);
			show_char_to_char($user,$user->in_room->people);
			$user->addtobuffer("~",ROOM_CONTAINER_CLOSE);
			$user->sendbuffer();
		}
	}
	
	public static function ql($user,$phrase) {
		commands::quicklook($user,$phrase);
	}
	
	public static function quicklook($user,$phrase) {
		if ($phrase=="") {
			$user->send($user->in_room->name,ROOM_NAME);
			$user->send($user->in_room->description,ROOM_DESC);
			$user->send("<br class=clear />");
		}
	}
	
	/* Game Commands */
	
	// Eventually we can make it difficult for people to quit but
	// For now, they do it directly
	public static function quit($user,$phrase) {
		ioHandler::doDisconnect($user->connector);
	}

}
		